from _decimal import Decimal

from weed_shop.core.models.dto import ProductWithQuantityDTO, DiscountDTO
from weed_shop.core.models.enums.currency import Currency
from weed_shop.core.price_calculation import calculate_total_summ


def test_calculate_total_summ(sample_products: list[ProductWithQuantityDTO], sample_discounts: list[DiscountDTO]):
    total_summ = calculate_total_summ(
        sample_products,
        maximum_bonus_discount_percent=20,
        discounts=sample_discounts,
        currency=Currency.thb,
    )
    assert total_summ == Decimal("306")


def test_calculate_total_summ_with_promocode(
    sample_products: list[ProductWithQuantityDTO], sample_discounts: list[DiscountDTO],
):
    total_summ = calculate_total_summ(
        sample_products,
        maximum_bonus_discount_percent=20,
        discounts=sample_discounts,
        currency=Currency.thb,
        promocode_percent=10,
    )
    assert total_summ == Decimal("275.37")


def test_calculate_total_summ_with_bonuses(
    sample_products: list[ProductWithQuantityDTO], sample_discounts: list[DiscountDTO],
):
    total_summ = calculate_total_summ(
        sample_products,
        maximum_bonus_discount_percent=20,
        discounts=sample_discounts,
        currency=Currency.thb,
        bonuses_amount=50,
    )
    assert total_summ == Decimal("256.00")


def test_calculate_total_summ_with_exchange(
    sample_products: list[ProductWithQuantityDTO], sample_discounts: list[DiscountDTO],
):
    total_summ = calculate_total_summ(
        sample_products,
        maximum_bonus_discount_percent=20,
        discounts=sample_discounts,
        currency=Currency.ton,
        exchange_rate=78.56,
        exchange_percent=2,
    )
    assert total_summ == Decimal("3.96")


def test_calculate_total_summ_with_btc_currency(
    sample_products: list[ProductWithQuantityDTO], sample_discounts: list[DiscountDTO],
):
    total_summ = calculate_total_summ(
        sample_products,
        maximum_bonus_discount_percent=20,
        discounts=sample_discounts,
        currency=Currency.btc,
        exchange_rate=50000,
    )
    assert total_summ == Decimal("0.00612000")